// 拉取筛选数据
import { onMounted, ref } from 'vue'
import { findSubCategoryFilter } from '@/api/category'
import { useRoute } from 'vue-router'
export function useLoadFilterData () {
  const subData = ref(null)
  const route = useRoute()
  async function loadSubData () {
    const res = await findSubCategoryFilter(route.params.id)
    subData.value = res.result
    // 添加 全部 分类
    subData.value.saleProperties.forEach((item) => {
      item.properties.unshift({
        name: '全部',
        id: null
      })
    })
    // 给每一个item项都添加一个seleted字段
    subData.value.saleProperties.forEach(item => {
      item.properties.forEach(i => {
        i.selected = false
      })
    })
  }
  onMounted(() => {
    loadSubData()
  })
  return {
    subData
  }
}
